/*
 * @Author: Jimmy
 * @LastModifiedBy: Jimmy
 * @Date: 2024-04-14 21:08:58
 * @LastEditTime: 2024-07-07 15:08:45
 * @FilePath: /nest_study/web/src/views/system/user/columns.tsx
 */
import ShowDictionary from "@/components/dictionary_label";
import { sexList } from "./dictionary";
import { Button, Flex, Switch } from "antd";
import { formateLocalDateTime } from "@/utils";

export const columns = (update: Function, edit: Function, remove: Function, reset: Function) => [
    {
        title: '账号',
        dataIndex: 'userName',
        ellipsis: true
    },
    {
        title: '昵称',
        dataIndex: 'nickName',
        ellipsis: true
    },
    {
        title: '联系电话',
        dataIndex: 'phone',
        ellipsis: true
    },
    {
        title: '性别',
        dataIndex: 'sex',
        width: 60,
        render: (text: any, _row: any, _index: number) => <ShowDictionary list={sexList} label={'label'} value={text} />,
    },
    {
        title: '部门',
        dataIndex: 'depts',
        ellipsis: true,
        render: (text: any, _row: any, _index: number) => {
            let deptNames: string[] = [];
            if (text.length) {
                text.map((item: any) => {
                    deptNames.push(item.name);
                })
            }
            return <>{deptNames.join(',') || ''}</>
        }
    },
    {
        title: '角色',
        dataIndex: 'roles',
        ellipsis: true,
        render: (text: any, _row: any, _index: number) => {
            let roleNames: string[] = [];
            if (text.length) {
                text.map((item: any) => {
                    roleNames.push(item.name);
                })
            }
            return <>{roleNames.join(',') || ''}</>
        }
    },
    {
        title: '邮箱',
        dataIndex: 'email',
        ellipsis: true
    },
    {
        title: '状态',
        dataIndex: 'status',
        width: 100,
        render: (text: any, _row: any, _index: number) =>
            <Switch checked={text == '0' ? true : false} onChange={() => update(_row)} checkedChildren="启用" unCheckedChildren="关闭" />,
    },
    {
        title: '登录时间',
        dataIndex: 'loginTime',
        width: 165,
        render: (text: any, _row: any, _index: number) => <p>{text && formateLocalDateTime(text)}</p>,
    },
    {
        title: '创建时间',
        dataIndex: 'createTime',
        width: 165,
        render: (text: any, _row: any, _index: number) => <p>{formateLocalDateTime(text)}</p>,
    },
    {
        title: '操作',
        dataIndex: 'action',
        width: 200,
        align: "center" as "center",
        fixed: 'right' as 'right',
        render: (_text: any, _row: any, _index: number) => <Flex gap={10} align="center">
            <Button size="small" type="primary" onClick={() => edit(_row)}>编辑</Button>
            <Button size="small" type="primary" onClick={() => remove(_row)} danger>删除</Button>
            <Button size="small" type="primary" onClick={() => reset(_row)}>密码重置</Button>
        </Flex>,
    }
]